﻿using System.Linq;
using System.Text;
using System.Collections.Generic;
using Microsoft.SqlServer.Dts.Runtime;

namespace NazTek.Documenter.Ssis.Control
{
    internal class SsisConnectionList : List<SsisConnection>
    {
        internal SsisConnectionList(Connections connections)
        {
            foreach (var cn in connections)
                Add(new SsisConnection(cn));
        }
        internal string GetName(string id)
        {
            return this.Where(s => s.Id == id).Select(s => s.Name).FirstOrDefault();
        }
        internal string GetDoc()
        {
            var doc = new StringBuilder();
            foreach (var cn in this)
                cn.BuildDoc(doc);
            return string.Format("<h5>Package Connections<ul>{0}</ul></h5>",doc);
        }
    }
    internal class SsisConnection
    {
        internal string Id { get; set; }
        internal string Name { get; set; }
        internal string ConnectionString { get; set; }
        internal SsisConnection(ConnectionManager connectionManager)
        {
            Id = connectionManager.ID;
            Name = connectionManager.Name;
            ConnectionString = connectionManager.ConnectionString;
        }
        internal void BuildDoc(StringBuilder doc)
        {
            doc.AppendFormat("<li>[{0}]: {1}</li>", Name, ConnectionString);
        }
    }
}